import React from 'react';

let instance = null;

export class ActionManger {
  constructor() {
    if(!instance) {
      instance = this;
      this.executers = {};
    }
    return instance;
  }

  call(action) {
    if(this.executers[action.moduleType]) {
      for (var i = 0; i < this.executers[action.moduleType].length; i++) {
        this.executers[action.moduleType][i].execute(action);
      }
    }
  }

  //注册executer
  registeExecuter(moduleType, executers) {
    if(!this.executers[moduleType]) {
      this.executers[moduleType] = [];
    }
    if(typeof(executers) == 'array') {
      this.executers[moduleType].concat(executers);
    }
    else {
      this.executers[moduleType].push(executers);
    }
  }
}
new ActionManger();
module.exports = instance;
